Skip to content

fix: group contiguous note edits into a single undo step#4524

Open
patbyte wants to merge 3 commits into
cybersemics:mainfrom
patbyte:fix/note-undo-grouping
Open

fix: group contiguous note edits into a single undo step#4524
patbyte wants to merge 3 commits into
cybersemics:mainfrom
patbyte:fix/note-undo-grouping

Conversation

@patbyte

@patbyte patbyte commented Jul 6, 2026

Copy link
Copy Markdown

Route note edits through editThought instead of setDescendant so consecutive note changes merge in the undo stack, and mark toggleNote as non-undoable.

This PR fixes #4479.

Changes:

  • Note edits now dispatch editThought when the note value thought already exists, so they use the existing directional undo chunking logic
  • Empty note creation is no longer undoable
  • Added undo/redo coverage for note additions, deletes, replacements, and empty-note creation

Route note edits through editThought instead of setDescendant so
consecutive note changes merge in the undo stack, and mark toggleNote
as non-undoable.
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Vercel preview: https://em-h6mey5gwb-cybersemics.vercel.app

@raineorshine raineorshine requested a review from BayuAri July 6, 2026 15:24
@BayuAri

BayuAri commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Issue A: Undo is splitted into 2 stacks for replacing a word on Notes

- One
- Two

Step to Reproduce

  1. Create a new Note under One
  2. Type The world of beautiful birds
  3. Change the birds word into people
  4. Click Undo

Current behavior

The first Undo the replaced word becomes p
The second Undo the word is reverted to birds

Fast.type.mov
Slow.Type.mov

Expected behavior

The first Undo should revert to the original birds

@BayuAri

BayuAri commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Issue B: Backspace / Delete is not working and caret is moved to the end of the thought text after Undo on the first thought

Step to Reproduce

  1. Create a new Note under One
  2. Type The world of birds
  3. Select the word world
  4. Change the word into cage
  5. Click Undo to revert back to world
  6. Hit Delete button on the keyboard several time

Current behavior

Nothing happens.
The caret is moved to the end of the thought text.
Workaround: move the caret next to the desired word to make it works again to delete/backspace.

Issue.B.Backspace.Delete.is.not.working.after.Undo.MP4

Expected behavior

Backspace/delete should work after Undo action.
The caret should be placed where it left off

@BayuAri

BayuAri commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Issue C: Undo a new Notes creation is Undoing the last action prior the creating the new Notes but leaving the empty Notes

Step to Reproduce

  1. Create a new thought
  2. Add a text One
  3. Click Add Notes button
  4. Click Undo

Current behavior

One text is undone.
Newly created empty Note remains.
Undo again deletes the thought.

Issue.C.Undo.a.new.Notes.creation.is.Undoing.the.last.action.prior.the.creating.the.new.Notes.but.leaving.the.empty.Notes.MP4

Expected behavior

Newly created empty note should be deleted

@BayuAri

BayuAri commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Issue D: Backspace/Delete button on the keyboard deletes the thought space.

- One
- Two

Step to Reproduce

  1. Create a new Notes on Thought Two
  2. Type Hello World
  3. Change Hello to Great
  4. Tap Undo
  5. Tap Backspace/Delete button on the keyboard

Current behavior

Thought space is deleted.
Two text is merged onto the above One along with the Notes
This is related to Issue B

Issue.D.Backspace.Delete.button.on.the.keyboard.deletes.the.thought.space.MP4

Expected behavior

Backspace/Delete button on the keyboard should serve to delete the character before the caret.

@BayuAri BayuAri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raineorshine

Copy link
Copy Markdown
Contributor

@raineorshine
Question about Issue A, is this intended as the implementation of Replacements → separate undo steps

This raises a good question, though for the purpose of this issue we are just aiming to reproduce the undo/redo behavior that currently exists for normal thoughts. So for any edit to a note, check how many undo/redo steps are created if the same edit is applied to a normal thought.

That should be enough to figure out the intended functionality, but to answer your specific question about Issue A, you have come up with a case that I don't think I had considered yet, and I'm not sure how this is handled in the code currently. I think the code currently categorizes edits based on the string length delta:

ADD: a (1) → ab (2)
DELETE: ab (2) → a (1)
REPLACE: a (1) → b (1)

Issue A is unique in that it is a replacement, but the number of characters are not the same. I think birds (5) → people (6) would currently be categorized by an addition, which is probably wrong (i.e. a bug in normal thought undo/redo). Categorizing it as a replacement so that it gets its own undo step and is not merged with other contiguous additions makes more sense.

However, that's all out of scope for this issue, whose main purpose is to implement baseline undo/redo chunking to notes. This was understandably not so clear from my hasty bug report.

@raineorshine

Copy link
Copy Markdown
Contributor

@patbyte Is this ready for review or are you still working on it? Once ready, please use the GitHub "Request Review" feature to request a behavioral review from Bayu. Then I will review once behavior is confirmed.

Thanks!

image

@patbyte patbyte requested a review from BayuAri July 10, 2026 06:23
@BayuAri

BayuAri commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Issue E: Unable to partial select on the note text

Step to Reproduce

  1. Create a new thought with text
  2. Add a note with text
  3. Place the caret on the note
  4. Double click on any word on the note or click and drag to select

Current behavior

Selection highlight is flashing and it is not selecting the text

Issue.E.Unable.to.partial.select.on.the.note.text.mov

Expected behavior

User should be able to select text with double click or click and drag

@patbyte

patbyte commented Jul 10, 2026

Copy link
Copy Markdown
Author

Hi @BayuAri , What about the issues from A to D?
All working well?

@BayuAri

BayuAri commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Hi @BayuAri , What about the issues from A to D? All working well?

I'll report that on my Review comment at the end of the testing.
Will get there.

I log the issue per comment so we can reference this easily on the Review comment linking.

@BayuAri BayuAri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patbyte
Test result
List of issues:

Testing is blocked by Issue E

Fixed

Fixed

Partially fixed

This is considered as fixed because the caret is placed at the beginning of the notes, however, hitting Backspace when the caret is at the beginning of the Notes will delete the note and merge the notes text into thought text.

Step to Reproduce

- One 
- Two
  1. Create a note under Thought Two
  2. Add a text onto the Notes
  3. Place the caret at the beginning of the Notes text
  4. Hit Backspace on the keyboard

Current behavior

Notes text merges with the Thought Text.

Expected behavior

@raineorshine
Please help with the expected result.
This refers to the behavior of Thought but it is kind of weird when on Notes.
I think nothing should happen here.
This is not a regression issue but behavioral question because this exist on main

New regression issue:

@patbyte

patbyte commented Jul 10, 2026

Copy link
Copy Markdown
Author

@BayuAri , Thanks for your testing.
Let me fix all of them and will let you know.

@patbyte patbyte requested a review from BayuAri July 10, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undo/redo directional chunking for notes

3 participants